package com.dzt.androidframework.changeskin.lib.attr;

import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dzt.androidframework.changeskin.lib.ResourceManager;
import com.dzt.androidframework.changeskin.lib.SkinManager;


/**
 * Created by zhy on 15/9/28.
 */
public enum SkinAttrType {
	BACKGROUND("background") {
		@Override
		public void apply(View view, String resName) {
			Drawable drawable = getResourceManager().getDrawableByName(resName);
			if (drawable == null)
				return;
			view.setBackground(drawable);
		}
	}, COLOR("textColor") {
		@Override
		public void apply(View view, String resName) {
			ColorStateList colors = getResourceManager().getColorStateList(resName);
			if (colors == null)
				return;
			((TextView) view).setTextColor(colors);
		}
	}, SRC("src") {
		@Override
		public void apply(View view, String resName) {
			if (view instanceof ImageView) {
				Drawable drawable = getResourceManager().getDrawableByName(resName);
				if (drawable == null)
					return;
				((ImageView) view).setImageDrawable(drawable);
			}
		}
	};

	String attrType;

	SkinAttrType(String attrType) {
		this.attrType = attrType;
	}

	public String getAttrType() {
		return attrType;
	}


	public abstract void apply(View view, String resName);

	public ResourceManager getResourceManager() {
		return SkinManager.getInstance().getResourceManager();
	}
}
